package com.aramis.mydytt.util

import android.content.Context
import com.tencent.mmkv.MMKV

/**
 * Description: MMKVUtil
 * @author lizhidan
 * Created: 2021/5/25
 */
object MMKVUtil {
    private var myMMKV: MMKV? = null

    fun init(context: Context) {
        MMKV.initialize(context.filesDir.absolutePath + "/ar_mmkv")
        myMMKV = MMKV.mmkvWithID("my_dytt")
    }

    fun putString(key: String, value: String?) {
        myMMKV?.putString(key, value)
    }

    fun putBoolean(key: String, value: Boolean) {
        myMMKV?.putBoolean(key, value)
    }

    fun putInt(key: String, value: Int) {
        myMMKV?.putInt(key, value)
    }

    fun putFloat(key: String, value: Float) {
        myMMKV?.putFloat(key, value)
    }

    fun getString(key: String, defVal: String? = null): String? = myMMKV?.getString(key, defVal) ?: defVal

    fun getBoolean(key: String, defVal: Boolean = false): Boolean = myMMKV?.getBoolean(key, defVal) ?: defVal

    fun getInt(key: String, defVal: Int = 0): Int = myMMKV?.getInt(key, defVal) ?: defVal

    fun getFloat(key: String, defVal: Float = 0f): Float = myMMKV?.getFloat(key, defVal) ?: defVal
}